/**
 * 系统业务参数获取
 */
package com.cr.backbone.util;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

/**
 * @project RaedNote
 * @version 1.0
 * @company
 * @fileDescribe
 * @fileType UtilsConfigProps UtilsConfigProps.java
 * @author xianghua.hu
 * @date 2012-5-23 下午04:21:29
 */
/**
 * @author huxh
 * 
 */
public class UtilsConfigProperties {

	private boolean reload=false;//是否需要重新加载
	private static UtilsConfigProperties utilsConfigProperties=null;
	private Properties props = new Properties();
	private static final String PROPERTIES_fILE_NAME="config.properties";
	
	public UtilsConfigProperties(){
		load();
	}
	
	
	
	/**
	 * 单例
	 * @methodDescribe
	 * @return
	 * @author xianghua.hu
	 * @date 2012-5-23
	 */
	public static  UtilsConfigProperties  getInstance(){
		if(utilsConfigProperties==null){
			utilsConfigProperties=new UtilsConfigProperties();
			
		}
		return utilsConfigProperties;
	}
	
	public void load() {
		
//		InputStream in = getProperties.class.getClassLoader().getResourceAsStream(
//	    "config.properties");
//	这一句换个写法试试：

	props = new Properties();
	String url = this.getClass().getClassLoader().getResource(
			PROPERTIES_fILE_NAME).toString().substring(6);
	  String empUrl = url.replace("%20", " ");// 如果你的文件路径中包含空格，是必定会报错的
	  System.out.println(empUrl);
	  InputStream in = null;
	  try {
	   in = new BufferedInputStream(new FileInputStream(empUrl));
	   props.load(in);
	  } catch (FileNotFoundException e1) {
	   e1.printStackTrace();
	  } catch (IOException e1) {
	   e1.printStackTrace();
	  }
	  
	  reload=false;//不需要重新加载
	}
	
	/**
	 * 获取 config.properties 文件中参数值 
	 * @param key
	 * @return
	 * @author xianghua.hu
	 * @date 2012-5-24
	 */
	public String getProperty(String key){
		props.keys();
		return props.getProperty(key);
	}
	
	/**
	 * 获取 config.properties 文件中参数值 
	 * @param key
	 * @return
	 * @author xianghua.hu
	 * @date 2012-5-24
	 */
	public Set<Object> getKeys(){
		return props.keySet();
	}
	
	
//	public boolean put(){
//		utils
//	}
	
	
	public static void main(String[] args){
		String from=UtilsConfigProperties.getInstance().getProperty("mail.from");
		String password=UtilsConfigProperties.getInstance().getProperty("mail.password");
		String password11=UtilsConfigProperties.getInstance().getProperty("11mail.password");
		System.out.println(from);
		System.out.println(password);
		System.out.println(password11);
	}
	
}
